const { defineConfig } = require('@vue/cli-service')
let {list}=require('./src/mock')
module.exports = defineConfig({
  transpileDependencies: true,
  devServer:{
    setupMiddlewares(middlewares,{app}){
      app.get('/api/list',(req,res)=>{
        const {input='',page=1,pageSize=10}=req.query
        const data=list.filter(v=>{
          if(input!==''){
            return v.name.includes(input)
          }else{
            return v
          }
        })
        res.send({
          list:data.slice((page-1)*pageSize,page*pageSize),
          tiao:data.length
        })
      })
      app.get('/api/teled/:id',(req,res)=>{
        const {id}=req.params
        list=list.filter(v=>v.id!==id)
        res.send({
          code:200
        })
      })
      return middlewares
    }
  }
})
